package org.dtrd.modules.evaluation.entity.bean;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.modules.evaluation.constant.Evaluation;
import org.dtrd.modules.evaluation.entity.po.DtrdEntEvaluationRdHappy;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author QR
 * @Date 2021/11/1 3:36 PM
 */
@ApiModel("总体幸福感评估")
@Data
public class HappyInfo {

    @ApiModelProperty("记录id")
    private Integer dataId;

    @ApiModelProperty("患者id")
    private Integer patientId;

    @ApiModelProperty("输入分值列表")
    private List<Integer> input;

    @ApiModelProperty("总分")
    private Integer total;

    @ApiModelProperty("等级")
    private String level;

    @ApiModelProperty("输出内容")
    private String output;

    @ApiModelProperty("创建时间")
    private Date createTime;

    public HappyInfo parseFromPo(DtrdEntEvaluationRdHappy po) {
        dataId = po.getDataId();
        patientId = po.getPatientId();
        ArrayList<Integer> answerList = new ArrayList<>(Evaluation.ProblemNum.HAPPY.getNum());
        String answerStr = po.getInput();
        if (!StrUtil.isBlank(answerStr)){
            String[] strings = answerStr.split(",");
            for (String s : strings) {
                answerList.add(Integer.parseInt(s));
            }
        }
        input = answerList;
        level = po.getLevel();
        total = po.getTotal();
        output = po.getOutput();
        createTime = po.getCreateTime();
        return this;
    }
}
